import { request } from '../request';

const auth = {
  username: 'whoami',
  password: 'justsoso'
};

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchGetAllDish(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.Food.DishList>({
    url: '/dish',
    method: 'get',
    params
  });
}

export const getDishSearch = (search: string) => {
  return request({
    url: `/dish/www/cache?search=${search}`,
    method: 'get',
    auth
  });
};

export function getFirstPage() {
  return request({
    url: '/firstpage',
    method: 'get'
  });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchAddDish(data?: Api.Food.Dish) {
  return request<Api.Food.Dish>({
    url: '/dish',
    method: 'post',
    data
  });
}

export function fetchDeleteDish(id: number) {
  return request<Api.Food.Dish>({
    url: `/${id}/dish`,
    method: 'delete'
  });
}

export function fetchDeleteBatchDish(ids: string[]) {
  return request<Api.Food.Dish>({
    url: `/dish`,
    method: 'delete',
    data: {
      ids
    }
  });
}

export function fetchEditDish(id: number, data?: Api.Food.Dish) {
  return request<Api.Food.Dish>({
    url: `/${id}/dish`,
    method: 'put',
    data
  });
}
